{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7b506a6b-762d-4c81-b18e-26ba3aa86767",
   "metadata": {},
   "source": [
    "Chapter 08\n",
    "# lambda函数\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4d5af63e-8f22-480b-bfdb-393e8e81ade6",
   "metadata": {},
   "outputs": [],
   "source": [
    "my_list = [1, 2, 3, 4, 5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f23069ba-8c15-4fde-9145-1bcb2557ed22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "# 将列表中的所有元素加 1\n",
    "list_plus_1 = list(map(lambda x: x+1, my_list))\n",
    "print(list_plus_1)  \n",
    "# [2, 3, 4, 5, 6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "14c0f749-073f-43f9-8bf6-eb0e4f906178",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25]\n"
     ]
    }
   ],
   "source": [
    "# 将列表中的所有元素分别求平方\n",
    "list_squared = list(map(lambda x: x**2, my_list))\n",
    "print(list_squared)\n",
    "# [1, 4, 9, 16, 25]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
